package document.apps;

import antlr.RecognitionException;
import antlr.TokenStreamException;
import document.model.Book;
import metamodel.ClassNode;
import metamodel.TraversalUtils;
import metamodel.coreservices.TreeModelAdapter;

import javax.swing.*;
import javax.swing.tree.TreeModel;
import java.io.IOException;

/**
 * User: fleipold
 * Date: 28-Nov-2007
 * Time: 22:48:10
 */
public class ExampleTree1 {
    private final  ClassNode traversalModel;


    private void buildUI(TreeModelAdapter model) {
         JFrame frame=new JFrame();

         JSplitPane split=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);


        JTree tree = new JTree();
        tree.setCellRenderer(model.getRenderer());
        tree.setModel(model);
        frame.getContentPane().add(new JScrollPane(tree));

         frame.pack();
         frame.setTitle("A tree Example");
         frame.setBounds(0,0,600,600);

         frame.setVisible(true);

         frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
     }


    public ExampleTree1() throws TokenStreamException, RecognitionException, IOException {
         traversalModel = TraversalUtils.parse(getClass().getResourceAsStream("full.trv"));
        Book book = Book.buildExample();
        buildUI(new TreeModelAdapter(traversalModel, book));
        


    }

    public static void main(String[] args) throws TokenStreamException, RecognitionException, IOException {
        new ExampleTree1();
    }

}